<?php
namespace Home\Controller;
use Think\Controller;
class OrderController extends Controller {
   public function getAllOrder(){
        $orderModel=D('order');
        $order=$orderModel->relation('get_user_info')->order("uid")->select();
        //echo json_encode($data);  
        $this->order=$order;
        $this->display();
    }
    public function getOrderById(){
    	$oid=$_GET['orderid'];
        $orderModel=D('order');
        $order=$orderModel->relation('get_user_info')->where("orderid='$oid'")->find();
        // echo json_encode($data);
        $this->order=$order;
        $this->display();
    }
     public function delOrder(){
    $oid=$_GET['orderid'];
    $orderModel=M('order');
    if($orderModel->delete($oid)){
        $this->success('删除成功');
    }else{
        $this->error('删除失败');
    }
   }

   public function setState($orderid){
    $orderModel=M('order');
    $data['orderstate']=0;
    if($orderModel->where("orderid=$orderid")->save($data)){
        $this->success('修改状态成功');
    }else{
        $this->error('修改状态失败');
    }
   }
   public function upState($orderid){
    $orderModel=M('order');
    $data['orderstate']=1;
    if($orderModel->where("orderid=$orderid")->save($data)){
        $this->success('修改状态成功');
    }else{
        $this->error('修改状态失败');
    }
   }


   public function updateOrder($orderid){
    $orderModel=D('order');
    $order=$orderModel->relation('get_user_info')->where("orderid=$orderid")->find();
    $this->order=$order;
    $this->display();
  // var_dump($order);
    // echo json_encode($one);
   }
//   public function updateOrderInfo(){
//     $up=M('order');
//     if($up->create()){
//         if($up->save()){
//             $this->success('修改成功','getAllOrder');
//         }else{
//             $this->error('修改失败');
//         }
//     }
// }



 public function updateOrderInfo(){

            $data=$_POST;
            $orderid=$data['orderid'];
            //dump($data);
           // dump($file);
                    
            $orderModel = M('order'); // 实例化User模型
            // 要修改的数据对象属性赋值
            //$userModel->create();   // 根据表单提交的POST数据创建数据对象
            //dump($data);
        //$result=$userModel->where("id=$id")->save($data);

            //没有修改头像
            $result=$orderModel->where("orderid=$orderid")->save($data);
  
       
        if($result){
             $this->success('修改成功！','getAllOrder');
             }
            else{
                $this->error('修改失败！');
                }
    }
    
}